package org.example.gradlemultipledatasourcedemo.service.impl;

import com.github.pagehelper.Page;
import gradle.mybatis.common.response.ApiResponse;
import gradle.mybatis.common.utils.PageUtil;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.example.gradlemultipledatasourcedemo.config.config2.DynamicRoutingDataSource;
import org.example.gradlemultipledatasourcedemo.mapper.jp.StarWordMapper;
import org.example.gradlemultipledatasourcedemo.model.dto.StarWordQueryDto;
import org.example.gradlemultipledatasourcedemo.model.vo.StarWordVo;
import org.example.gradlemultipledatasourcedemo.service.StarWordService;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class StarWordImpl implements StarWordService {

    @Resource
    private StarWordMapper starWordMapper;


    @Override
    public ApiResponse<List<StarWordVo>> listPage(StarWordQueryDto starWordQueryDto) {
        Page<List<StarWordVo>> page = PageUtil.startPage(starWordQueryDto.getPageNum(), starWordQueryDto.getPageSize());
        DynamicRoutingDataSource.set("jpDataSource");
        List<StarWordVo> listPage = starWordMapper.listPage(starWordQueryDto);

        return ApiResponse.success(listPage, page);
    }

}
